<template>
	<view class="columnbox wdh-100 content">
		<view v-for="(item,index) in list" :key='index' class="columnbox one-info">
			<view class="rowbox wdh-100 spb">
				<view class="title">{{item.name}}</view>
				<view class="rowbox">
					<view @click="editInfo(item.id)" class="def-col rowbox title">
						<u-icon name="edit-pen" color="#57bd6a" size="36rpx"></u-icon>
						编辑
					</view>
					<view @click="deletInfo(item.id)" class="rowbox title" style="margin-left: 40rpx;color: #a3a5a1;">
						<u-icon name="trash" color="#a3a5a1" size="36rpx"></u-icon>
						删除
					</view>
				</view>
			</view>
			<view class="rowbox wdh-100 jus">
				<view class="info-detail">支付{{item.price}}元</view>
				<view class="info-detail">赠送{{item.song}}元</view>
				<view class="info-detail">折扣{{item.discount}}折</view>
			</view>
		</view>
		<view class="wdh-100" style="height: 200rpx;"></view>
		<view class="add-btn rowbox def-bgcol" @click="addRecharge">
			添加
		</view>
		<view class="weekNotice" v-if="showWeekNotice">
			<view class="">
				{{buymsg}}
			</view>
			<view class="btncont">
				<u-button v-if="!isIos" type="primary" size="mini" text="续费" @click="handleShowAndrRenw"></u-button>
				<u-button v-if="isIos" type="primary" size="mini" text="联系客服" @click="handleKefu"></u-button>
			</view>
		</view>
		<IosKefu :show="showIosKefu" :type="matype" @close="closeIosKefu"></IosKefu>
		<AndrTaocan :show="showAndrTaocan" :taocanid="7" @close="closeAndrTaocan" @refsh="handlerefsh"></AndrTaocan>
	</view>
</template>

<script>
	import IosKefu from '@/components/ioskefu.vue'
	import AndrTaocan from '@/components/andrtaocan.vue'
	export default {
		components: {
			IosKefu,
			AndrTaocan
		},
		data() {
			return {
				buymsg: '',
				showAndrTaocan: false,
				matype: '',
				showIosKefu: false,
				isIos: false,
				showWeekNotice: false,
				refreshflag: false,
				list: []
			};
		},
		onShow() {
			const info = wx.getSystemInfoSync()
			this.isIos = !(info.system.indexOf('Android') > -1)
			this.getStrorInfo()
			if (this.refreshflag) {
				this.refreshflag = false
				this.list = []
				this.getInfo()
			}
		},
		onLoad() {
			this.getInfo()
		},
		methods: {

			handlerefsh() {
				this.getStrorInfo()
			},
			handleShowAndrRenw() {
				this.showAndrTaocan = true
			},
			closeAndrTaocan() {
				this.showAndrTaocan = false
			},
			handleKefu() {
				this.showIosKefu = true
				this.matype = 'hyimg'
			},
			closeIosKefu() {
				this.showIosKefu = false
			},
			getStrorInfo() {
				this.$req.post('/shanghu/userInfo', {
					uid: uni.getStorageSync('uid')
				}).then((res) => {
					let data = res.data.data
					this.buymsg = data.hytitle
					if (data.hyweak == 2) {
						this.showWeekNotice = true
					}
					if (data.hystrong === 2) {
						let flag = true
						if (uni.getStorageSync('rechargetaoendtime')) {
							var ctime = new Date().getTime()
							if (ctime > uni.getStorageSync('rechargetaoendtime')) {
								uni.removeStorageSync('rechargetaoendtime')
							} else {
								flag = false
							}
						}
						if (this.isIos) {
							this.matype = 'hyimg'
							this.showIosKefu = flag
						} else {
							this.showAndrTaocan = flag
						}

						if (!uni.getStorageSync('rechargetaoendtime')) {
							let endTime = new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 *
								60 *
								1000 - 1); // 当天23:59
							uni.setStorageSync('rechargetaoendtime', endTime)
						}
					}

				})
			},
			editInfo(id) {
				uni.navigateTo({
					url: './add?id=' + id
				})
			},
			getInfo() {
				this.$req.post('/shanghu/blocks', {
					shanghuid: uni.getStorageSync('userInfo').shanghuid
				}).then(res => {
					this.list = res.data.data
				})
			},
			addRecharge() {
				uni.navigateTo({
					url: '/pages/recharge/add'
				})
			},
			deletInfo(id) {
				uni.showModal({
					title: '是否要删除该套餐',
					success: (res) => {
						if (res.confirm) {
							this.$req.post('/shanghu/blockpacekagedel', {
								id: id
							}).then(res => {
								this.list = []
								this.getInfo()
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.weekNotice {
		padding: 15rpx 30rpx;
		position: fixed;
		bottom: 130rpx;
		left: 0;
		z-index: 100;
		width: 100%;
		background-color: #fdf6ec;
		color: #f9ae3d;
		font-size: 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.content {
		min-height: 100vh;
		background: #f6f6f6;
		justify-content: flex-start;
		padding-bottom: 200rpx;
	}

	.add-btn {
		color: #fff;
		width: 710rpx;
		height: 90rpx;
		border-radius: 20rpx;
		position: fixed;
		bottom: 40rpx;
		left: 20rpx;
	}

	.one-info {
		background: #fff;
		margin-top: 20rpx;
		padding: 20rpx 20rpx;
		border-radius: 10rpx;
		width: 710rpx;
	}

	.title {
		font-size: 32rpx;
	}

	.info-detail {
		margin-top: 32rpx;
		font-size: 28rpx;
		color: #3e3e3e;
		margin-right: 40rpx;
		width: 200rpx;
	}
</style>